use crate::config::{AUTH_URL, CLIENTID};
use crate::utils::{helper::redirect_to, url::get_query_param};
use stylist::yew::styled_component;
use yew::prelude::*;

#[derive(Properties, PartialEq, Clone)]
pub struct AuthContextProps {
    #[prop_or_default]
    pub children: Html,
}
#[styled_component]
pub fn AuthContext(props: &AuthContextProps) -> Html {
    use_effect_with((), move |_| {
        if get_query_param("access_code").is_none() {
            let _ = redirect_to(&format!("{}?client_id={}", AUTH_URL, CLIENTID));
        }
    });
    html! {
        <div>
            {props.children.clone()}
        </div>
    }
}
